package com.chenjun.common.util;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class PrintData {
	
	public static void printCommonData(Object obj, HttpServletResponse response){
		response.setHeader("Content-type", "text/html;charset=utf-8");
		response.setContentType("text/html;charset=utf-8");
		try {
			PrintWriter out = response.getWriter();
			out.println(obj);
            out.flush();
            out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void printJsonData(Object obj, String dateFormat, HttpServletResponse response){
		response.setHeader("Content-type", "text/html;charset=utf-8");
		response.setContentType("text/html;charset=utf-8");
		Gson gson = new GsonBuilder().setDateFormat(dateFormat).create();
		try {
			PrintWriter out = response.getWriter();
			out.println(gson.toJson(obj));
            out.flush();
            out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
